<?php

class Kit_Controller extends WakEngineController {

    function _setUp() {
		$this->id=$this->response->shiftNode();
        // kit analysis
        $this->response->kit=new WakKitFolder($this->id);
        // setting breadcrumb links
        $this->response->addBreadCrumb('Kits','kits');
        $kitpath='';
        foreach (explode('.',$this->id) as $part) {
            $kitpath.=$part.'.';
            $this->response->addBreadCrumb($part,'kit/'.substr($kitpath,0,-1));
        }
        // diagnostic
        if (!$this->response->kit->isValid()) {
            $this->_setAction('badkit');
        }
    }

    /**
     * kit home/index
     */
    function index() {
		$this->response->view='kit';
        //$subkits=$this->response->kit->subkits(); print_r($subkits);
        //$this->response->subkits=$subkits;
        if ($this->response->kit->hasTests())
            $this->response->tests=$this->response->kit->getTestsReport();
    }

	/**
	* an invalid kit page
	*/
	public function badkit() {
        return true;
	}/**/

	/**
	 * unit tests details
	 */
    function tests() {
        $this->response->addBreadCrumb('Tests','kit/'.$this->id.'/tests');
        if ($this->response->kit->hasTests())
            $this->response->tests=$this->response->kit->getTestsReport();

    }

	function cfg() {
		//$this->response->view='kit.cfg';
        $this->response->addBreadCrumb('wak.ini','kit/'.$this->id.'/cfg');
        // save sent data
        if ($this->_isPost()) {
            $this->response->saved=
                $this->response->kit->setIni($_POST['ini']);
        }
		$this->response->cfg=$this->response->kit->getIni();
        return true;
	}

	/**
	 * edit a kit's tool config
	 */
	function toolCfg($name) {
		Webappkit::loadKit('webappkit.fs.core');
		$this->response->name=$name;
        $this->response->addBreadCrumb($name.'.tool.ini','kit/'.$this->id.'/toolcfg/'.$name);
        if ($this->_isPost()) {
            // saving data
            $this->response->saved=
                $this->response->kit->setToolIni($name,$_POST['ini']);
        }
		$this->response->toolcfg=$this->response->kit->getToolIni($name);
	}
}
